package com.auto.learning.fragment;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

import com.auto.learning.R;
import com.auto.learning.activity.AnchorInfoActivity;
import com.auto.learning.activity.MySleepModeActivity;
import com.auto.learning.activity.PlayActivity;
import com.auto.learning.activity.PlayListActivity;
import com.auto.learning.adapter.PlayFragmentChapterAdapter;
import com.auto.learning.bean.AnchorBean;
import com.auto.learning.bean.AnchorBookBean;
import com.auto.learning.bean.BookBean;
import com.auto.learning.bean.CaseType;
import com.auto.learning.bean.ListenModeBean;
import com.auto.learning.bean.PlayFragmentChapterBean;
import com.auto.learning.bean.ResponeResult;
import com.auto.learning.bean.SelectionVo;
import com.auto.learning.bean.ShareBean;
import com.auto.learning.bean.UserVipInfo;
import com.auto.learning.event.BreakPointTipsEvent;
import com.auto.learning.event.BuySuccessEvent;
import com.auto.learning.event.CheckStatusEvent;
import com.auto.learning.event.EventBus;
import com.auto.learning.event.Handle;
import com.auto.learning.event.NowPlayEvent;
import com.auto.learning.event.PlayTypeEvent;
import com.auto.learning.event.ProgressEvent;
import com.auto.learning.event.RefreshPlayListEvent;
import com.auto.learning.event.listener.DialogListener;
import com.auto.learning.net.Cache;
import com.auto.learning.net.HttpCommonInfo;
import com.auto.learning.net.HttpRequestHelper;
import com.auto.learning.pay.UserBuyUtils;
import com.auto.learning.service.DownLoadManager;
import com.auto.learning.service.MusicPlayManager;
import com.auto.learning.service.MyUserInfo;
import com.auto.learning.store.core.StaticReference;
import com.auto.learning.thread.pool.Pool;
import com.auto.learning.tools.CommonMethod;
import com.auto.learning.tools.FastBlur;
import com.auto.learning.tools.TemporaryVariable;
import com.auto.learning.tools.Utils;
import com.auto.learning.view.MyCustomListView;
import com.auto.learning.view.ObservableScrollView;
import com.auto.learning.view.ObservableScrollView.ScrollViewListener;
import com.auto.learning.view.RoundImageView;
import com.auto.learning.view.SharedPreferencesUtils;
import com.baidu.mobstat.StatService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.squareup.otto.Subscribe;
import com.squareup.otto.ThreadEnforcer;

/**
 * 滑动修改后的版本
 * @author wangjianjun
 * 2016年3月28日09:31:51
 */
public class PlayFragment extends Fragment implements OnClickListener{

	private final static int UPDATE_PLAY_TIME = 3;
	private final static int GETCACHEDATA_SUCCESS = 5;
	private final static int DOWNLOAD_PROGRESS = 6;
	private final static int PULL_FROM_TOP = 7;
	private final static int UPDATE_UI_VIEW = 8;
	private final static int ANCHOR_FAVOR = 9;
	public final static int ANCHOR_FAVOR_SUCCESS = 10;
	public final static int ANCHOR_FAVOR_FAIL = 11;
	public final static int ANCHOR_HEAD_IMAGE_CLICK = 12;
	public final static int GETCACHEDATA_FAIL = 13;
	public final static int BUY_SUCCESS = 14;
		
	private int bookId;
	private RelativeLayout play_contain,play_contain_back;
	private ImageView f_image_guoqi,image_render;
	
	
	private RoundImageView image_face,image_face_back;
	private RadioGroup segment_text;
	private RadioButton button_one,button_two,button_three;
	private View view2,headView,top_view;
	private TextView tv_bookname,tv_current_time,tv_total_time,tv_download,tv_current_time_back,tv_total_time_back,tv_break_piont_tips;
	private ImageView image_play,image_download,image_sleep_close,image_play_list,image_play_back;
	private SeekBar my_seekbar,my_seekbar_back;
	private LinearLayout linear_download,liner_dome;
	private LinearLayout rel_bottom;
	
	private MyCustomListView listview_chapters;
	private PlayFragmentChapterAdapter chapterAdapter;
	private ArrayList<SelectionVo> chapterList = new  ArrayList<SelectionVo>();
	private ArrayList<AnchorBean> anchorList = new  ArrayList<AnchorBean>();
	
	private PlayFragmentChapterBean playFragmentChapterBean = new PlayFragmentChapterBean();
	
	
	private ListenModeBean listenModeBean = new ListenModeBean();

	private boolean isPlaying = false;
	private GestureDetector gd;
	private DisplayImageOptions options;
	
	ObservableScrollView scroll_main;
	
	private int break_point_continue = 0;
	
	Handle handler = new Handle(getActivity()){
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case UPDATE_PLAY_TIME:
				NowPlayEvent nowPlayBean = (NowPlayEvent)msg.obj;
				if (nowPlayBean != null && listenModeBean != null && bookId == MusicPlayManager.getInstance(getActivity()).isPlayingBookId()[0]) {
					break_point_continue = 0;
					tv_current_time.setText(nowPlayBean.getCurrentPosition());
					tv_total_time.setText(nowPlayBean.getTotalDuration());
					my_seekbar.setEnabled(true);
					my_seekbar.setMax(nowPlayBean.getTotal());
					my_seekbar.setProgress(nowPlayBean.getCurrent());
					
					tv_current_time_back.setText(nowPlayBean.getCurrentPosition());
					tv_total_time_back.setText(nowPlayBean.getTotalDuration());
					my_seekbar_back.setEnabled(true);
					my_seekbar_back.setMax(nowPlayBean.getTotal());
					my_seekbar_back.setProgress(nowPlayBean.getCurrent());
				}
				break;
			case HttpRequestHelper.GETDATA_SUCCESS:
				ResponeResult result = (ResponeResult) msg.obj;
				listenModeBean = new Gson().fromJson(result.getData(), new TypeToken<ListenModeBean>() {}.getType());
				try {
					ImageLoader.getInstance().displayImage(listenModeBean.getNationImg(),f_image_guoqi);
					ImageLoader.getInstance().displayImage(listenModeBean.getFaceImgPlay(),image_face);
					ImageLoader.getInstance().displayImage(listenModeBean.getFaceImgPlay(),image_face_back);
//					ImageLoader.getInstance().displayImage(listenModeBean.getFaceImg(),image_render);
//					((PlayActivity)getActivity()).updateBackImage(listenModeBean.getFaceImg());
					((PlayActivity)getActivity()).setNeedBuy(listenModeBean.getNeedBuy());
					((PlayActivity)getActivity()).setCanRead(listenModeBean.getCanRead());
					dealBottom();
					tv_bookname.setText(listenModeBean.getBookName());
					playFragmentChapterBean.setPriceTag(listenModeBean.getPriceTag());
					initChapterUI(listenModeBean.getSectionList());
//					initBottom(listenModeBean.getSectionList());
					//缓存到本地
					cacheListenMode2Local(listenModeBean);
					Cache.cacheFaceImgPlay2Local(listenModeBean.getBookId(), listenModeBean.getFaceImgPlay());
					initAnchorUI(listenModeBean.getAnchorList());
					updateUi();
					handler.postDelayed(new CheckStatus(), 1000);
				} catch (Exception e) {
					e.printStackTrace();
				}
				break;
			case GETCACHEDATA_SUCCESS:
				if (listenModeBean.getBookId() != 0) {
					try {
						ImageLoader.getInstance().displayImage(listenModeBean.getNationImg(),f_image_guoqi);
						ImageLoader.getInstance().displayImage(listenModeBean.getFaceImgPlay(),image_face,options);
						ImageLoader.getInstance().displayImage(listenModeBean.getFaceImgPlay(),image_face_back,options);
						((PlayActivity)getActivity()).updateBackImage(listenModeBean.getFaceImg());
						((PlayActivity)getActivity()).setNeedBuy(listenModeBean.getNeedBuy());
						((PlayActivity)getActivity()).setCanRead(listenModeBean.getCanRead());
						time = HttpRequestHelper.BLUR_DEFAULT_TIMES;
						tv_bookname.setText(listenModeBean.getBookName()+"");
						dealBottom();
						playFragmentChapterBean.setPriceTag(listenModeBean.getPriceTag());
						initChapterUI(listenModeBean.getSectionList());
//						initBottom(listenModeBean.getSectionList());
						initAnchorUI(listenModeBean.getAnchorList());
						updateUi();
						if (TemporaryVariable.downLoadedList.contains(bookId)) {
							image_download.setBackgroundResource(R.drawable.xiazaiok);
							tv_download.setText("已下载");
						}else {
							image_download.setBackgroundResource(R.drawable.xiazai2);
							tv_download.setText("下载");
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
				getData();
				break;
			case GETCACHEDATA_FAIL:
				getData();
				break;
			case DOWNLOAD_PROGRESS:
				ProgressEvent event = (ProgressEvent)msg.obj;
				if (event.getBookId() == bookId) {
					/*if (event.getCurrentRatio() == 100) {
						image_download.setBackgroundResource(R.drawable.xiazaiok);
						tv_download.setText("已下载");
					}else {
						linear_download.setEnabled(false);
						tv_download.setText(event.getCurrentRatio()+"%");
						image_download.setBackgroundResource(R.anim.download_stute);
						AnimationDrawable _animaition = (AnimationDrawable)image_download.getBackground();
						_animaition.setOneShot(false);   
						_animaition.start();
					}*/
					if (buttonList != null && buttonList.size() == 1) {
						if (event.getCurrentRatio() == 100) {
							handler.postDelayed(new Runnable() {
								@Override
								public void run() {
									dealBottom();
								}
							}, 500);
						}else {
							buttonList.get(0).setText(event.getCurrentRatio()+"%");
						}
					}
				}
				break;
			case -2:
				BookBean bookBean = (BookBean) msg.obj;
				if (bookBean != null) {
//					ArrayList<BookBean> m_list = new ArrayList<BookBean>();
//					m_list.add(bookBean);
//					MusicPlayManager.getInstance(getActivity()).setPlayList(m_list).setBookId(msg.arg1).setChapterId(msg.arg2).play();
					((PlayActivity)getActivity()).playDialog(bookBean, msg.arg2, 1);
				}
				break;
			case UPDATE_UI_VIEW:
				boolean m_isPlaying = (boolean) msg.obj;
				if (MusicPlayManager.getInstance(getActivity()).getPlayList() != null) {
					int ids[] = MusicPlayManager.getInstance(getActivity()).isPlayingBookId();
					if (bookId == ids[0]) {
						isPlaying = m_isPlaying;
						MusicPlayManager.getInstance(getActivity()).setPlaying(isPlaying);
						if (ids[0] != 0) {
							setBookId(ids[0]);
						}
						try {
							updateUi();
						} catch (Exception e) {
							e.printStackTrace();
						}
						if (chapterAdapter != null) {
							chapterAdapter.notifyDataSetChanged();
							listview_chapters.notifyChange();
						}
					}
				}
				break;
			case 20:
				int position = msg.arg1;
				MusicPlayManager manager = MusicPlayManager.getInstance(getActivity());
				if (manager.getPlayList() != null && manager.getPlayList().size() > 0) {
					int[] ids = manager.isPlayingBookId();
					if (bookId == ids[0]) {
						if (ids[1] == chapterList.get(position).getSectionId()) {
							manager.pause();
						} else {
							if(TemporaryVariable.downLoadedList.contains(bookId)||CommonMethod.getNetworkState(getActivity())!=0){
								manager.setBookAndChapterIds(bookId, chapterList.get(position).getSectionId()).play();
							}else{
								EventBus.getEventBus("m_play_stute").post(false);
								if(MusicPlayManager.getInstance(getActivity()).isPlaying()){
									MusicPlayManager.getInstance(getActivity()).pause();
								}
								CommonMethod.makeNotice(getActivity(),getResources().getString(R.string.connect_err_io));
							}
						
						}
					} else {
						playCharpter(bookId,position);
					}
				} else {
					playCharpter(bookId,position);
				}
				break;
			case ANCHOR_FAVOR:
				List<NameValuePair> l_params = new ArrayList<NameValuePair>();
				l_params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(getActivity(), HttpRequestHelper.USERID, 0))));
				l_params.add(new BasicNameValuePair("anchorId", String.valueOf(msg.obj.toString())));
				l_params.add(new BasicNameValuePair("bookId", String.valueOf(bookId)));
				HttpRequestHelper.addAnchorFavorNum(getActivity(), l_params, handler, ANCHOR_FAVOR_SUCCESS, ANCHOR_FAVOR_FAIL, msg.obj.toString());
				break;
			case ANCHOR_FAVOR_SUCCESS:
				ResponeResult _respone = (ResponeResult) msg.obj;
				for (int i = 0; i < anchorList.size(); i++) {
					if ((anchorList.get(i).getId()+"").equals(_respone.getData().toString())) {
						anchorList.get(i).setFavorNum(anchorList.get(i).getFavorNum() + 1);
						anchorList.get(i).setIsFavor(2);
						break;
					}
				}
				if (chapterAdapter != null) {
					chapterAdapter.notifyDataSetChanged();
					listview_chapters.notifyChange();
				}
				break;
			case ANCHOR_FAVOR_FAIL:
				CommonMethod.makeNotice(getActivity(), msg.obj.toString());
				break;
			case ANCHOR_HEAD_IMAGE_CLICK:
				try {
					AnchorBean anchorBean = (AnchorBean) msg.obj;
					Intent mIntent = new Intent(getActivity(), AnchorInfoActivity.class);
					mIntent.putExtra("m_anchor_bean", anchorBean);
					getActivity().startActivity(mIntent);
				} catch (Exception e) {
					e.printStackTrace();
				}
				break;
			case PULL_FROM_TOP:
				play_contain.setVisibility(View.INVISIBLE);
				tempBefY = msg.arg1;
				params.setMargins(0, msg.arg1 , 0, 0);
				play_contain.setLayoutParams(params);
				break;
			case BUY_SUCCESS:
				if (listenModeBean != null) {
					if (msg.arg1 == 0 || listenModeBean.getBookId() == msg.arg1) {
						listenModeBean.setNeedBuy(1);
						((PlayActivity)getActivity()).setNeedBuy(1);
						dealBottom();
					}
				}
				break;
			case 21:
				if (msg.obj != null) {
					CommonMethod.makeNotice(getActivity(), msg.obj.toString());
				}
				break;
			}
		};
	};
	
	
	
	
	View view = null;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.play_fragment2, null);
		initImageLoader();
		initView(view);
		registerEvent();
		setUserVisibleHint(true);
		return view;
	}
	
	List<Button> buttonList;
	private void dealBottom(){
		if (TemporaryVariable.downLoadedList.contains(listenModeBean.getBookId())) {
			rel_bottom.setVisibility(View.GONE);
			buttonList = Utils.setBookType(rel_bottom, ((PlayActivity)getActivity()).getTypeList(1), getActivity());
		}else {
			if (listenModeBean.getNeedBuy() == 1) {
				buttonList = Utils.setBookType(rel_bottom, ((PlayActivity)getActivity()).getTypeList(3), getActivity());
			}else {
				UserVipInfo vipInfo = MyUserInfo.getInstance().getUserInfoBean().getVipInfo();
				if (vipInfo != null) {
					switch (vipInfo.getVipType()) {
					case 1:
						buttonList = Utils.setBookType(rel_bottom, ((PlayActivity)getActivity()).getTypeList(4), getActivity());
						break;
					case 2:
					case 3:
						buttonList = Utils.setBookType(rel_bottom, ((PlayActivity)getActivity()).getTypeList(2), getActivity());
						break;
					}
				}else {
					buttonList = Utils.setBookType(rel_bottom, ((PlayActivity)getActivity()).getTypeList(2), getActivity());
				}
			}
		}
	}
	
	
	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		super.setUserVisibleHint(isVisibleToUser);
		if (isVisibleToUser) {
			getPageCache();
		}
	}
	
	/***
	 * 获取被评论书的信息
	 */
	public Map<String, Object> getCommentBookInfo(){
		Map<String, Object> map = new HashMap<String, Object>();
		if (listenModeBean != null && listenModeBean.getBookId() > 0) {
			map.put("bookId", listenModeBean.getBookId());
			map.put("bookName", listenModeBean.getBookName());
			map.put("imgFace", listenModeBean.getFaceImg());
			map.put("imgFacePlay", listenModeBean.getFaceImgPlay());
		}
		return map;
	}
	
	private void getData(){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(getActivity(), HttpRequestHelper.USERID, 0))));
		params.add(new BasicNameValuePair(HttpRequestHelper.BOOKID, String.valueOf(bookId)));
		HttpRequestHelper.executeHttpData(getActivity(), HttpRequestHelper.LISTEN_MODE, params, handler, HttpRequestHelper.GETDATA_SUCCESS, 21);
	}
	
	
	
	private int time = HttpRequestHelper.BLUR_DEFAULT_TIMES;
	/***
	 * 处理高斯模糊
	 */
	public void applyBlur() {
		image_render.getViewTreeObserver().addOnPreDrawListener(
				new ViewTreeObserver.OnPreDrawListener() {
					@Override
					public boolean onPreDraw() {
						if (time > 0) {
							time --;
						} else {
							image_render.getViewTreeObserver().removeOnPreDrawListener(this);
						}
						image_render.buildDrawingCache();
						Bitmap bmp = image_render.getDrawingCache();
						FastBlur.blur(bmp, view2, getActivity());
						return true;
					}
			});
	}
	
	
	int befY = 0;
	int tempBefY = 0;
	LayoutParams params;
	Runnable runnable = new Runnable() {
		@Override
		public void run() {
			if (befY == tempBefY) {
				play_contain.setVisibility(View.VISIBLE);
			}else {
				play_contain.setVisibility(View.INVISIBLE);
			}
			handler.postDelayed(this, 500);
		}
	};
	
	@SuppressLint("ClickableViewAccessibility")
	private void initView(View view){
		if (view == null) {
			return;
		}
		handler.postDelayed(runnable, 100);
		gd = new GestureDetector(getActivity(), new MyGestureDetector());
		scroll_main = (ObservableScrollView) view.findViewById(R.id.scroll_main);
		scroll_main.setScrollViewListener(new ScrollViewListener() {
			
			@Override
			public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
				if (befY != y) {
					befY = y;
					handler.obtainMessage(PULL_FROM_TOP, y, 0).sendToTarget();
				}
			}
		});
		listview_chapters = (MyCustomListView) view.findViewById(R.id.listview_chapters);
		playFragmentChapterBean.setSelectionVoList(chapterList);
		playFragmentChapterBean.setAnchorList(anchorList);
		int type = (int) SharedPreferencesUtils.getParam(getActivity(),"chapter_type", 1);
		chapterAdapter = new PlayFragmentChapterAdapter(getActivity(), playFragmentChapterBean, handler,type == 3 ? 2 : 1,listenModeBean.getBookName());
		listview_chapters.setAdapter(chapterAdapter);
		rel_bottom = (LinearLayout) view.findViewById(R.id.rel_bottom);
		rel_bottom.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
			}
		});
		segment_text = (RadioGroup) view.findViewById(R.id.segment_text);
		
		headView = LayoutInflater.from(getActivity()).inflate(R.layout.play_fragment_head_top, null);
		
		linear_download = (LinearLayout) headView.findViewById(R.id.linear_download);
		image_download = (ImageView) headView.findViewById(R.id.image_download);
		tv_download = (TextView) headView.findViewById(R.id.tv_download);
		if (TemporaryVariable.downLoadedList.contains(bookId)) {
			image_download.setBackgroundResource(R.drawable.xiazaiok);
			tv_download.setText("已下载");
		}else {
			image_download.setBackgroundResource(R.drawable.xiazai2);
			tv_download.setText("下载");
		}
		my_seekbar = (SeekBar) view.findViewById(R.id.my_seekbar);
		my_seekbar.setEnabled(false);
		my_seekbar_back = (SeekBar) view.findViewById(R.id.my_seekbar_back);
		my_seekbar_back.setEnabled(false);
		tv_current_time = (TextView) view.findViewById(R.id.tv_current_time);
		tv_total_time = (TextView) view.findViewById(R.id.tv_total_time);
		tv_current_time_back = (TextView) view.findViewById(R.id.tv_current_time_back);
		tv_total_time_back = (TextView) view.findViewById(R.id.tv_total_time_back);
		tv_break_piont_tips = (TextView) view.findViewById(R.id.tv_break_piont_tips);
		button_one = (RadioButton) view.findViewById(R.id.button_one);
		button_two = (RadioButton) view.findViewById(R.id.button_two);
		button_three = (RadioButton) view.findViewById(R.id.button_three);
		switch (type) {
		case 1:
			segment_text.check(button_one.getId());
			break;
		case 2:
			segment_text.check(button_two.getId());
			break;
		case 3:
			segment_text.check(button_three.getId());
			break;
		}
		button_one.setOnClickListener(this);
		button_two.setOnClickListener(this);
		button_three.setOnClickListener(this);
		play_contain = (RelativeLayout) view.findViewById(R.id.play_contain);
		play_contain_back =  (RelativeLayout) view.findViewById(R.id.play_contain_back);
		play_contain.setBackgroundColor(getResources().getColor(R.color.black));
		play_contain_back.setBackgroundColor(getResources().getColor(R.color.black));
		play_contain.getBackground().setAlpha(0);
		play_contain_back.getBackground().setAlpha(127);
		params =(LayoutParams) play_contain.getLayoutParams();
		liner_dome = (LinearLayout) headView.findViewById(R.id.liner_dome);
		segment_text.setBackgroundColor(getResources().getColor(R.color.black));
		image_face = (RoundImageView) view.findViewById(R.id.image_face);
		image_face_back = (RoundImageView) view.findViewById(R.id.image_face_back);
		f_image_guoqi = (ImageView) headView.findViewById(R.id.f_image_guoqi);
		tv_bookname = (TextView) headView.findViewById(R.id.tv_bookname);
		image_play = (ImageView) view.findViewById(R.id.image_play);
		image_play_back = (ImageView) view.findViewById(R.id.image_play_back);
		
		
		linear_download.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				addDownload();
			}
		});
		try {
			ImageLoader.getInstance().displayImage(listenModeBean.getNationImg(),f_image_guoqi);
			ImageLoader.getInstance().displayImage(listenModeBean.getFaceImgPlay(),image_face);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		tv_bookname.setText(listenModeBean.getBookName());
		
		initAnchorUI(listenModeBean.getAnchorList());
		try {
			updateUi();
		} catch (Exception e) {
			e.printStackTrace();
		}
		image_play.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (listenModeBean == null || (listenModeBean != null && listenModeBean.getBookId() == 0)){
					return;
				}
				
				StatService.onEvent(getActivity(), "LogEventPlayBtnClick", "收听页的播放按钮");
				MusicPlayManager manager = MusicPlayManager.getInstance(getActivity());
				if(listenModeBean.getNeedBuy() == 2&&!TemporaryVariable.downLoadedList.contains(listenModeBean.getBookId())){
					if(manager.getPlayList() != null && manager.getPlayList().size() > 0){
						int ids[] = manager.isPlayingBookId();
						if (ids[0] != bookId) {
							new UserBuyUtils(((Activity)getActivity()), listenModeBean.getBookId(), listenModeBean.getPriceTag(),listenModeBean.getBookName()).buy();
							return;
						}
					}else{
						new UserBuyUtils(((Activity)getActivity()), listenModeBean.getBookId(), listenModeBean.getPriceTag(),listenModeBean.getBookName()).buy();
						return;
					}
				}
				if (manager.getPlayList() != null && manager.getPlayList().size() > 0) {
					int ids[] = manager.isPlayingBookId();
					if (ids[0] == bookId) {
						MusicPlayManager.getInstance(getActivity()).pause();
					} else {
						if (manager.needCheckNet()) {
							CommonMethod.showMobileNetTips(TemporaryVariable.getTopActivity(), new DialogListener() {
								
								@Override
								public void otherButtonClick(Dialog dialog) {
									dialog.dismiss();
									HttpCommonInfo.M_NET_DIALOG_SHOW = false;
									MusicPlayManager.getInstance(getActivity()).setShowNetTips(true);
								}
								
								@Override
								public void okButtonClick(Dialog dialog) {
									dialog.dismiss();
									HttpCommonInfo.M_NET_DIALOG_SHOW = false;
									MusicPlayManager.getInstance(getActivity()).setShowNetTips(false);
									onPlayClick();
								}
								
								@Override
								public void cancelButtonClick(Dialog dialog) {
									dialog.dismiss();
									HttpCommonInfo.M_NET_DIALOG_SHOW = false;
									MusicPlayManager.getInstance(getActivity()).setShowNetTips(true);
								}
							});
						}else {
							onPlayClick();
						}
					}
				}else {
					onPlayClick();
				}
			}
		});
		my_seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				if (fromUser == true) {
					seekBar.setProgress(progress);
					EventBus.getEventBus("m_fase").post(progress);
				}
			}
		});
		image_sleep_close = (ImageView) view.findViewById(R.id.image_sleep_close);
		image_sleep_close.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				StatService.onEvent(getActivity(), "LogEventTimerBtnClick", "定时播放");
				Intent mIntent = new Intent(getActivity(), MySleepModeActivity.class);
				getActivity().startActivity(mIntent);
			}
		});
		image_play_list = (ImageView) view.findViewById(R.id.image_play_list);
		image_play_list.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				StatService.onEvent(getActivity(), "LogEventPlayListBtnClick", "播放列表");
				Intent intent = new Intent(getActivity(), PlayListActivity.class);
				getActivity().startActivity(intent);
			}
		});
		LinearLayout linear_view_top = (LinearLayout) view.findViewById(R.id.linear_view_top);
		linear_view_top.addView(headView);
		
		breakPointView();  
		
//		listview_chapters.addHeadView(headView);
//		applyBlur();
	}
	
	public void addDownload(){
		if (listenModeBean != null && !TemporaryVariable.downLoadedList.contains(listenModeBean.getBookId()) && CommonMethod.checkUserLogin(getActivity())) {
			StatService.onEvent(getActivity(), "LogEventTypeDownloadButtonClic", "下载按钮");
			int size = 0;
			if(listenModeBean!=null&&listenModeBean.getSectionList()!=null){
				List<SelectionVo> list = listenModeBean.getSectionList();
				for (SelectionVo item : list) {
					size += (item.getDoubiSize() + item.getProSize() + item.getEnSize());
				}
				if (size > 0) {
//					DownLoadManager.getInstance(getActivity()).setNeedDownLoadBookId(bookId).prepareBefore(size);
					DownLoadManager.getInstance(getActivity()).setContext(getActivity()).prepareBefore(bookId,size);
				}
			}
		}
	
	}
	
	/**
	 * 点击断点的处理操作
	 */
	private void breakPointView(){
		if (break_point_continue == 1) {
			int currentTime = (int) SharedPreferencesUtils.getParam(getActivity(), HttpRequestHelper.CONTINUE_PLAY_BOOK_TIME, 0);
			int totalTime = (int) SharedPreferencesUtils.getParam(getActivity(), HttpRequestHelper.CONTINUE_PLAY_BOOK_TOTAL_TIME, 0);
			if (currentTime > 0 && totalTime > 0 && totalTime >= currentTime) {
				my_seekbar.setMax(totalTime);
				my_seekbar_back.setMax(totalTime);
				my_seekbar.setProgress(currentTime);
				my_seekbar_back.setProgress(currentTime);
				tv_current_time.setText(CommonMethod.getNowTime(currentTime));
				tv_current_time_back.setText(CommonMethod.getNowTime(currentTime));
				tv_total_time.setText(CommonMethod.getNowTime(totalTime));
				tv_total_time_back.setText(CommonMethod.getNowTime(totalTime));
			}
		}
	}
	
	public void onPlayClick(){
		BookBean bookBean = new BookBean();
		bookBean.setBookId(bookId);
		bookBean.setSectionList(listenModeBean != null ? listenModeBean.getSectionList() : null);
		bookBean.setBookName(listenModeBean.getBookName());
		bookBean.setSlogan(listenModeBean.getSlogan());
		bookBean.setFaceImg(listenModeBean.getFaceImg());
		bookBean.setFaceImgPlay(listenModeBean.getFaceImgPlay());
		((PlayActivity)getActivity()).getLocalBook(bookBean);
	}
	
	private void initChapterUI(List<SelectionVo> list){
		if (list == null) {
			return;
		}
		if (chapterList != null && list.size() > 0) {
			chapterList.clear();
			chapterList.addAll(list);
			int type = (int) SharedPreferencesUtils.getParam(getActivity(),"chapter_type", 1);
			if (!TextUtils.isEmpty(list.get(0).getTitle()) && (type == 1 || type == 2)) {
				chapterAdapter.setType(1);
			} else if (!TextUtils.isEmpty(list.get(0).getTitleEn()) && type == 3){
				chapterAdapter.setType(2);
			} else {
				if (!TextUtils.isEmpty(list.get(0).getTitle())) {
					chapterAdapter.setType(1);
				} else if (!TextUtils.isEmpty(list.get(0).getTitleEn())){
					chapterAdapter.setType(2);
				}
			}
			for (int i = 0; i < chapterList.size(); i++) {
				if (chapterAdapter.getType() == 1) {
					if (TextUtils.isEmpty(chapterList.get(i).getTitle())) {
						chapterList.remove(i);
						i --;
					}
				}else if (chapterAdapter.getType() == 2) {
					if (TextUtils.isEmpty(chapterList.get(i).getTitleEn())) {
						chapterList.remove(i);
						i --;
					}
				}
			}
			if (chapterAdapter != null) {
				chapterAdapter.notifyDataSetChanged();
				listview_chapters.notifyChange();
			}
		}
	}
	
	@SuppressLint("NewApi")
	private void initBottom(List<SelectionVo> list) throws Exception{
		if (list == null) {
			return;
		}
		if (list.size() > 0) {
			SelectionVo vo = list.get(0);
			if (vo.getProSec() == 0) {
				CommonMethod.setBackground(button_one, getResources().getDrawable(R.drawable.zhuanyeboyin_none));
				button_one.setEnabled(false);
			}else {
				CommonMethod.setBackground(button_one, getResources().getDrawable(R.drawable.radio_left_1));
				button_one.setEnabled(true);
			}
			if (vo.getDoubiSec() == 0) {
				CommonMethod.setBackground(button_two, getResources().getDrawable(R.drawable.doubiboyin_none));
				button_two.setEnabled(false);
			}else {
				CommonMethod.setBackground(button_two, getResources().getDrawable(R.drawable.radio_mid_2));
				button_two.setEnabled(true);
			}
			if (vo.getEnSec() == 0) {
				CommonMethod.setBackground(button_three, getResources().getDrawable(R.drawable.yingwenboyin_none));
				button_three.setEnabled(false);
			}else {
				CommonMethod.setBackground(button_three, getResources().getDrawable(R.drawable.radio_right_3));
				button_three.setEnabled(true);
			}
		}
	}
	
	private void initAnchorUI(List<AnchorBean> list){
		try {
			if (list == null) {
				return;
			}
			if (anchorList != null && list.size() > 0) {
				anchorList.clear();
				anchorList.addAll(list);
				if (chapterAdapter != null) {
					chapterAdapter.notifyDataSetChanged();
				}
				listview_chapters.notifyChange();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void updateUi() throws Exception{
		int playingBookId[] = MusicPlayManager.getInstance(getActivity()).isPlayingBookId();
		if (playingBookId[0] != 0 && playingBookId[0] == bookId) {
			if (playingBookId[2] == 0) {
				image_play.setImageBitmap(CommonMethod.readBitMap(getActivity(), R.drawable.playing_big));
				image_play_back.setImageBitmap(CommonMethod.readBitMap(getActivity(), R.drawable.playing_big));
			}else {
				image_play.setImageBitmap(CommonMethod.readBitMap(getActivity(), R.drawable.play_big));
				image_play_back.setImageBitmap(CommonMethod.readBitMap(getActivity(), R.drawable.play_big));
			}
		} else {
			image_play.setImageBitmap(CommonMethod.readBitMap(getActivity(), R.drawable.play_big));
			image_play_back.setImageBitmap(CommonMethod.readBitMap(getActivity(), R.drawable.play_big));
		}
	}
	
	@Subscribe
	public void onEventPlayStute(Boolean isPlaying){
		handler.obtainMessage(UPDATE_UI_VIEW, isPlaying).sendToTarget();
	}
	
	@Subscribe
	public void onEventPlayTime(NowPlayEvent nowPlayBean) {
		handler.obtainMessage(UPDATE_PLAY_TIME, nowPlayBean).sendToTarget();
	}
	
	@Subscribe
	public void onEventProgress(ProgressEvent event){
		handler.obtainMessage(DOWNLOAD_PROGRESS, event).sendToTarget();
	}
	
	@Subscribe
	public void onEventPlayBeanChange(String temp){
		MusicPlayManager manager = MusicPlayManager.getInstance(getActivity());
		int[] ids = manager.isPlayingBookId();
		if (isPlaying && !temp.equals(bookId+"")) {
			Intent intent = new Intent(getActivity(), PlayActivity.class);
			intent.putExtra("bookId", ids[0]);
			intent.putExtra("faceImg", TextUtils.isEmpty(manager.getFaceImage()) ? "" : manager.getFaceImage());
			intent.putExtra("canRead", manager.getCanRead());
			
			int needBuy=1;
			//传递是否免费书籍判断
			for (int i = 0; i < manager.getPlayList().size(); i++) {
				if(manager.isPlayingBookId()[0] == manager.getPlayList().get(i).getBookId()){
					needBuy = manager.getPlayList().get(i).getNeedBuy();
				}
			}
			intent.putExtra("needBuy", needBuy);

			startActivity(intent);
		}
	}
	
	@Subscribe
	public void onEventPlayTypeRefresh(PlayTypeEvent event) {
		chooseButton();
	}
	
	@Subscribe
	public void onEventRefreshPlayList(RefreshPlayListEvent event){
		if (chapterAdapter != null) {
			int type = (int) SharedPreferencesUtils.getParam(getActivity(),"chapter_type", 1);
			if (type == 3) {
				chapterAdapter.setType(2);
			}else {
				chapterAdapter.setType(1);
			}
			chapterList.clear();
			if (listenModeBean != null && listenModeBean.getSectionList() != null) {
				chapterList.addAll(listenModeBean.getSectionList());
				if (chapterList != null && chapterList.size() > 0) {
					for (int i = 0; i < chapterList.size(); i++) {
						if (chapterAdapter.getType() == 1) {
							if (TextUtils.isEmpty(chapterList.get(i).getTitle())) {
								chapterList.remove(i);
								i--;
							}
						}else if (chapterAdapter.getType() == 2) {
							if (TextUtils.isEmpty(chapterList.get(i).getTitleEn())) {
								chapterList.remove(i);
								i--;
							}
						}
					}
					if (chapterAdapter != null) {
						chapterAdapter.notifyDataSetChanged();
						listview_chapters.notifyChange();
					}
				}
			}
		}
	}
	
	@Subscribe
	public void onShowBreakPointTipsEvent(BreakPointTipsEvent breakPointTipsEvent){
		if (tv_break_piont_tips.getVisibility() == View.GONE) {
			tv_break_piont_tips.setVisibility(View.VISIBLE);
			handler.postDelayed(new Runnable() {
				@Override
				public void run() {
					tv_break_piont_tips.setVisibility(View.GONE);
				}
			}, 2 * 1000);
		}
	}
	
	@Subscribe
	public void onEventBuySuccess(BuySuccessEvent buySuccessEvent){
		handler.obtainMessage(BUY_SUCCESS, buySuccessEvent.getBookId(), 0).sendToTarget();
	}
	
	
	public void registerEvent(){
		EventBus.getEventBus("m_play_stute" , ThreadEnforcer.MAIN).register(this);
		EventBus.getEventBus("m_now_play_time" , ThreadEnforcer.MAIN).register(this);
		EventBus.getEventBus("downloadProgress",ThreadEnforcer.MAIN).register(this);
		EventBus.getEventBus("m_play_bookbean_change", ThreadEnforcer.MAIN).register(this);
		EventBus.getEventBus("current_play_Type",ThreadEnforcer.MAIN).register(this);
		EventBus.getEventBus("refresh_PlayList",ThreadEnforcer.MAIN).register(this);
		EventBus.getEventBus("m_show_break_point_tips",ThreadEnforcer.MAIN).register(this);
		EventBus.getEventBus("m_buy_success",ThreadEnforcer.MAIN).register(this);
	}
	
	public void unRegisterEvent(){
		EventBus.getEventBus("m_play_stute" , ThreadEnforcer.MAIN).unregister(this);
		EventBus.getEventBus("m_now_play_time" , ThreadEnforcer.MAIN).unregister(this);
		EventBus.getEventBus("downloadProgress",ThreadEnforcer.MAIN).unregister(this);
		EventBus.getEventBus("m_play_bookbean_change", ThreadEnforcer.MAIN).unregister(this);
		EventBus.getEventBus("current_play_Type",ThreadEnforcer.MAIN).unregister(this);
		EventBus.getEventBus("refresh_PlayList",ThreadEnforcer.MAIN).unregister(this);
		EventBus.getEventBus("m_show_break_point_tips",ThreadEnforcer.MAIN).unregister(this);
		EventBus.getEventBus("m_buy_success",ThreadEnforcer.MAIN).unregister(this);
	}
	
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		unRegisterEvent();
	}
	
	
	
	public int getBookId() {
		return bookId;
	}

	public void setBookId(int bookId) {
		this.bookId = bookId;
	}
	
	public int getBreakPointContinue() {
		return break_point_continue;
	}

	public void setBreakPointContinue(int breakPointContinue) {
		this.break_point_continue = breakPointContinue;
	}
	
	private boolean canFling = true;

	/**
	 * 手势检测
	 * @author wangjianjun
	 */
	public class MyGestureDetector extends SimpleOnGestureListener {
		
		@Override
		public boolean onDown(MotionEvent e) {
			return true;
		}
		
		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
			if (canFling) {
				canFling = false;
				float minMove = 120; // 最小滑动距离
				float minVelocity = 0; // 最小滑动速度
				float beginX = e1.getX();
				float endX = e2.getX();
				if (beginX - endX > minMove && Math.abs(velocityX) > minVelocity) { // 左滑
					MusicPlayManager.getInstance(getActivity()).next();
				} else if (endX - beginX > minMove && Math.abs(velocityX) > minVelocity) { // 右滑
					MusicPlayManager.getInstance(getActivity()).previous();
				}
				handler.postDelayed(new Runnable() {
					@Override
					public void run() {
						canFling = true;
					}
				}, 1000);
			}
			return true;
		}
		
		@Override
		public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
			return true;
		}
	}
	
	/**
	 * 缓存章节和主播到本地
	 */
	private void cacheListenMode2Local(final ListenModeBean listenModeBean){
		Pool.getPool().execute(new Runnable() {
			
			@Override
			public void run() {
				if (listenModeBean != null) {
					try {
						if (StaticReference.mutilDBSupport.getDao(BookBean.class).queryForId(listenModeBean.getBookId()) == null) {
							BookBean bookBean = new BookBean();
							bookBean.setBookId(listenModeBean.getBookId());
							bookBean.setBookName(listenModeBean.getBookName());
							bookBean.setFaceImg(listenModeBean.getFaceImg());
							bookBean.setFaceImgPlay(listenModeBean.getFaceImgPlay());
							bookBean.setSlogan(listenModeBean.getSlogan());
							bookBean.setNationImg(listenModeBean.getNationImg());
							StaticReference.mutilDBSupport.getDao(BookBean.class).create(bookBean);
						}
					} catch (Exception e1) {
						e1.printStackTrace();
					}
					for (SelectionVo selectionVo : listenModeBean.getSectionList()) {
						try {
							SelectionVo vo = StaticReference.mutilDBSupport.getDao(SelectionVo.class).queryBuilder().where().eq("sectionId", selectionVo.getSectionId()).queryForFirst();
							if (vo != null) {
								vo.setTitle(selectionVo.getTitle());
								vo.setTitleEn(selectionVo.getTitleEn());
								vo.update();
							}else {
								StaticReference.mutilDBSupport.getDao(SelectionVo.class).create(selectionVo);
							}
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
					for (AnchorBean bean : listenModeBean.getAnchorList()) {
						try {
						     StaticReference.mutilDBSupport.getDao(AnchorBean.class).createOrUpdate(bean);
						     AnchorBookBean anchorBookBean =   StaticReference.mutilDBSupport.getDao(AnchorBookBean.class).queryBuilder().where().eq("bookId", listenModeBean.getBookId()).and().eq("anchorId", bean.getId()).queryForFirst();
						     if (anchorBookBean == null) {
						    	 anchorBookBean = new AnchorBookBean();
						    	 anchorBookBean.setAnchorId(bean.getId());
						    	 anchorBookBean.setBookId(listenModeBean.getBookId());
						    	 StaticReference.mutilDBSupport.getDao(AnchorBookBean.class).createOrUpdate(anchorBookBean);
							}
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				}
			}
		});
	}
	
	
	
	class CheckStatus implements Runnable{
		
		int i = 2;
		@Override
		public void run() {
			if (i > 0) {
				i --;
				EventBus.getEventBus("m_check_play_status").post(new CheckStatusEvent());
				handler.postDelayed(this, 1000);
			}
		}
	}
	
	/**
	 * 获取本页的缓存数据
	 */
	public void getPageCache(){
		
		Pool.getPool().execute(new Runnable() {
			
			@Override
			public void run() {
				try {
					BookBean bean = StaticReference.mutilDBSupport.getDao(BookBean.class).queryBuilder().where().eq("bookId", bookId).queryForFirst();
					if (bean != null) {
						listenModeBean.setBookId(bookId);
						listenModeBean.setBookName(bean.getBookName());
						listenModeBean.setFaceImg(bean.getFaceImg());
						listenModeBean.setFaceImgPlay(bean.getFaceImgPlay());
						listenModeBean.setNationImg(bean.getNationImg());
						listenModeBean.setSlogan(bean.getSlogan());
						listenModeBean.setFree(bean.getFree());
						listenModeBean.setPriceTag(bean.getPriceTag());
						listenModeBean.setNeedBuy(bean.getNeedBuy());
						listenModeBean.setCanRead(bean.getCanRead());
						List<SelectionVo> list_vo =	StaticReference.mutilDBSupport.getDao(SelectionVo.class).queryBuilder().where().eq("bookId", bookId).query();
						if (list_vo != null) {
							listenModeBean.setSectionList(list_vo);
						}
						List<AnchorBookBean> anchorList = StaticReference.mutilDBSupport.getDao(AnchorBookBean.class).queryBuilder().where().eq("bookId", bookId).query();
						ArrayList<AnchorBean> m_anchorList = new ArrayList<AnchorBean>();
						if (anchorList != null && anchorList.size() > 0) {
							for (AnchorBookBean anchorBookBean : anchorList) {
								AnchorBean m_anchor_list = StaticReference.mutilDBSupport.getDao(AnchorBean.class).queryForId(anchorBookBean.getAnchorId());
								m_anchorList.add(m_anchor_list);
							}
							if (m_anchorList != null) {
								listenModeBean.setAnchorList(m_anchorList);
							}
						}
						handler.sendEmptyMessage(GETCACHEDATA_SUCCESS);
					}else {
						handler.sendEmptyMessage(GETCACHEDATA_FAIL);
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public ShareBean getShareValue(){
		if (TextUtils.isEmpty(listenModeBean.getBookName()) || TextUtils.isEmpty(listenModeBean.getSlogan())) {
			return null;
		}
		ShareBean m_share = new ShareBean();
		m_share.setBookId(bookId);
		m_share.setUrl(HttpCommonInfo.MURL+"authorware-detail?id=" + bookId);
		m_share.setTitle(listenModeBean.getBookName());
		m_share.setContent(listenModeBean.getSlogan());
		m_share.setImageUrl(listenModeBean.getFaceImgPlay());
		return m_share;
	}
	
	private void initImageLoader(){
		options = new DisplayImageOptions.Builder()
		.showImageOnLoading(R.drawable.default_512)
		.showImageForEmptyUri(R.drawable.default_512)
		.showImageOnFail(R.drawable.default_512).cacheInMemory(true)
		.cacheOnDisk(true).considerExifParams(true)
		.bitmapConfig(Bitmap.Config.RGB_565).build();
	}
	
	/**
	 * 点击章节播放
	 */
	public void playCharpter(int bId,int position) {
		BookBean bean = new BookBean();
		bean.setBookId(bId);
		bean.setFaceImg(listenModeBean.getFaceImg());
		bean.setFaceImgPlay(listenModeBean.getFaceImgPlay());
		bean.setBookName(listenModeBean.getBookName());
		bean.setSlogan(listenModeBean.getSlogan());
		bean.setSectionList(listenModeBean.getSectionList());
		handler.obtainMessage(-2, bookId, position, bean).sendToTarget();
	}
	
	public void refreData(){
		getPageCache();
	}
	
	public ListenModeBean getListenModeBean() {
		return listenModeBean;
	}

	public void setListenModeBean(ListenModeBean listenModeBean) {
		this.listenModeBean = listenModeBean;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button_one:
			onClickChecked(1);
			break;
		case R.id.button_two:
			onClickChecked(2);
			break;
		case R.id.button_three:
			onClickChecked(3);
			break;
		}
	}
	
	private void onClickChecked(int type){
		try {
			int playBookId = MusicPlayManager.getInstance(getActivity()).isPlayingBookId()[0];
			if (bookId == playBookId && SharedPreferencesUtils.getParam(getActivity(), "chapter_type", 1).toString().equals(""+type)) {
				return;
			}
			if (checkTypeExist(type)) {
				SharedPreferencesUtils.setParam(getActivity(), "chapter_type", type);
				if (bookId == playBookId) {
					MusicPlayManager.getInstance(getActivity()).setChapterPosition(0).play();
				}else {
					BookBean bookBean = new BookBean();
					bookBean.setBookId(bookId);
					bookBean.setSectionList(listenModeBean != null ? listenModeBean.getSectionList() : null);
					bookBean.setBookName(listenModeBean.getBookName());
					bookBean.setSlogan(listenModeBean.getSlogan());
					bookBean.setFaceImg(listenModeBean.getFaceImg());
					bookBean.setFaceImgPlay(listenModeBean.getFaceImgPlay());
					((PlayActivity)getActivity()).getLocalBook(bookBean);
				}
				EventBus.getEventBus("refresh_PlayList").post(new RefreshPlayListEvent());
			}else {
				chooseButton();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private boolean checkTypeExist(int type){
		boolean flag = false;		
		List<SelectionVo> list = listenModeBean.getSectionList();
		if (list != null && list.size() > 0) {
			switch (type) {
			case 1:
				flag = list.get(0).getProSec() > 0;
				break;
			case 2:
				flag = list.get(0).getDoubiSec() > 0;
				break;
			case 3:
				flag = list.get(0).getEnSec() > 0;
				break;
			}
		}
		if (!flag) {
			CommonMethod.makeNotice(getActivity(), getResources().getString(R.string.text_notify));
		}
		return flag;
	}
	
	private void chooseButton(){
		int type = (int) SharedPreferencesUtils.getParam(getActivity(), "chapter_type", 1);
		switch (type) {
		case 1:
			button_one.setChecked(true);
			break;
		case 2:
			button_two.setChecked(true);
			break;
		case 3:
			button_three.setChecked(true);
			break;
		}
	}
	
}
